package daoIpmt;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import beans.Story;
import dao.StoryDao;
import utils.DataSourceUtils;

public class StoryDaoIpmt implements StoryDao {
	private DataSourceUtils data = new DataSourceUtils();
	private QueryRunner que = new QueryRunner(data.getDataSource());
	@Override
	public List<Story> getAllStory() {
		String sql="select *from story";
		try {
			List<Story> list = que.query(sql, new BeanListHandler<Story>(Story.class));
			return list;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	@Override
	public void addStory(Story s) {
		try {
			String sql="insert into story values(?,?,?,0)";
			String p=s.getPhotono();
			String u=s.getUsername();
			String b=s.getBody();
			System.out.println(p+","+u+","+b);		
			que.update(sql,p,u,b);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
